{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 作业2\n",
    "这里有gcForest的“官方实现”  \n",
    "https://github.com/kingfengji/gcForest  \n",
    "请部署有关代码并跑通一个demo，抓图实验过程。\n",
    "\n",
    "下面安装完deepforest包后，实验一下官方样例，鸢尾花数据集分类："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "id": "B09BE15C1DA44CCC973AE14009A6C4EC",
    "jupyter": {},
    "scrolled": false,
    "slideshow": {
     "slide_type": "slide"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2021-08-13 03:54:47.676] Start to fit the model:\n",
      "[2021-08-13 03:54:47.677] Fitting cascade layer = 0 \n",
      "[2021-08-13 03:54:48.450] layer = 0  | Val Acc = 97.996 % | Elapsed = 0.773 s\n",
      "[2021-08-13 03:54:48.456] Fitting cascade layer = 1 \n",
      "[2021-08-13 03:54:49.249] layer = 1  | Val Acc = 98.144 % | Elapsed = 0.792 s\n",
      "[2021-08-13 03:54:49.253] Fitting cascade layer = 2 \n",
      "[2021-08-13 03:54:49.909] layer = 2  | Val Acc = 97.921 % | Elapsed = 0.656 s\n",
      "[2021-08-13 03:54:49.909] Early stopping counter: 1 out of 2\n",
      "[2021-08-13 03:54:49.912] Fitting cascade layer = 3 \n",
      "[2021-08-13 03:54:50.561] layer = 3  | Val Acc = 97.476 % | Elapsed = 0.649 s\n",
      "[2021-08-13 03:54:50.561] Early stopping counter: 2 out of 2\n",
      "[2021-08-13 03:54:50.562] Handling early stopping\n",
      "[2021-08-13 03:54:50.563] The optimal number of layers: 2\n",
      "[2021-08-13 03:54:50.564] Start to evalute the model:\n",
      "[2021-08-13 03:54:50.565] Evaluating cascade layer = 0 \n",
      "[2021-08-13 03:54:50.598] Evaluating cascade layer = 1 \n",
      "\n",
      "Testing Accuracy: 98.667 %\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_digits\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "from deepforest import CascadeForestClassifier\n",
    "\n",
    "X, y = load_digits(return_X_y=True)\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)\n",
    "model = CascadeForestClassifier(random_state=1)\n",
    "model.fit(X_train, y_train)\n",
    "y_pred = model.predict(X_test)\n",
    "acc = accuracy_score(y_test, y_pred) * 100\n",
    "print(\"\\nTesting Accuracy: {:.3f} %\".format(acc))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "898634BDD6E347B99FFDA79D903A220F",
    "jupyter": {},
    "notebookId": "6115e78efe727700176c9a8c",
    "slideshow": {
     "slide_type": "slide"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
